package com.uniview.reactive.func;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

/**
 * @Author lux
 * @date: 2019/12/11
 * @desc: 函数式编程控制器
 */
@Component
public class RouterConfig {
    @Autowired
    TimeHandler timeHandler;
    @Bean
    public RouterFunction<ServerResponse> timerRouter() {
        return route(GET("/time"), req -> timeHandler.getTime(req))
                .andRoute(GET("/date"), req -> timeHandler.getDate(req))
                .andRoute(GET("/times"), timeHandler::sendTimePerSec);  // 这种方式相对于上一行更加简洁
    }
}
